package com.fourth_groups.shopping121store.ui.person.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.ui.person.utils.MyDataCleanManager;

public class SettingActivity extends AppCompatActivity {
    private LinearLayout linear_121;
    private LinearLayout linear_usearxy;
    private LinearLayout check_new;
    private LinearLayout linear_cash;
    private Button tulogin;
    private TextView seeting_text;
    private String cacheSize;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_setting);
        initview();
    }

    private void initview() {
        linear_121 = (LinearLayout) findViewById(R.id.linear_121);
        linear_usearxy = (LinearLayout) findViewById(R.id.linear_userxy);
        check_new = (LinearLayout) findViewById(R.id.check_new);
        linear_cash = (LinearLayout) findViewById(R.id.linear_cash);
        tulogin = (Button) findViewById(R.id.Tclogin);
        seeting_text = (TextView) findViewById(R.id.setting_text);
        try {
            cacheSize = MyDataCleanManager.getTotalCacheSize(getApplicationContext());
            seeting_text.setText(cacheSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        linear_121.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(SettingActivity.this,Linear_121.class);
                startActivity(intent);
            }
        });
        linear_usearxy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(SettingActivity.this,Linear_userxyActivity.class);
                startActivity(intent1);
            }
        });
      check_new.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(SettingActivity.this, "这是最新版本", Toast.LENGTH_SHORT).show();
          }
      });
        linear_cash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    if (cacheSize!=null) {
                        MyDataCleanManager.clearAllCache(SettingActivity.this);
                        seeting_text.setText("");
                        Toast.makeText(SettingActivity.this, "成功清理缓存", Toast.LENGTH_SHORT).show();
                    }
            }
        });
        tulogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (SettingActivity.this.isDestroyed()) {
                    Toast.makeText(SettingActivity.this, "退出登录", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        });
    }




}
